package org.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author TonySong
 * @date 2024/5/6 0006
 * @time 9:24
 */
@RestController
@Slf4j
@ConfigurationProperties("book")
public class ProviderController {

    @Value("${server.port}")
    private Integer port;
    @Value("${book.amount}")
    private Integer amount;

    @GetMapping("/order/{id}")
    public String order(@PathVariable("id") Integer id){
         log.info("order id:{}",id);
         if(this.amount>0) {
             System.out.println("当前的库存是：" + (--amount));
             return this.port + "购买成功！";
         }else{
             return "库存不足！";
         }

    }
}
